import { Account, Permission } from '@app/modules';
import { AuditBase } from '@app/types/entities';
import { Column, Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class Role extends AuditBase {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 50 })
  name: string;

  @ManyToMany(() => Account, (account) => account.roles)
  accounts: Account[];

  @ManyToMany(() => Permission, (permission) => permission.roles, { cascade: true })
  @JoinTable()
  permisions: Permission[];
}
